package com.aishua.aishuawallet.diydialog;

import android.app.Dialog;
import android.app.DialogFragment;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.aishua.aishuawallet.R;

/**
 * Created by aishua on 2018/8/10.
 */

public class TransferDialog extends DialogFragment {

    private View.OnClickListener sure_listener;

    public static TransferDialog newInstance(String address,String paywallet,String amount) {

        TransferDialog dialog = new TransferDialog();
        Bundle args = new Bundle();
        args.putString("address", address);
        args.putString("paywallet", paywallet);
        args.putString("amount", amount);
        dialog.setArguments(args);
        return dialog;
    }

    public void setSureButtonListener(View.OnClickListener listener) {

        this.sure_listener = listener;
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {

        String address = getArguments().getString("address");
        String paywallet = getArguments().getString("paywallet");
        String amount = getArguments().getString("amount");
        LayoutInflater inflaterDl = LayoutInflater.from(getActivity());
        LinearLayout layout = (LinearLayout) inflaterDl.inflate(R.layout.transfer_dialog, null);

        //对话框
        final Dialog dialog = new Dialog(getActivity(), R.style.common_dialog_style);
        dialog.setContentView(layout);
        Window dialogWindow = dialog.getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        dialogWindow.setGravity(Gravity.BOTTOM);
        lp.width = LinearLayout.LayoutParams.MATCH_PARENT; // 宽度
        lp.height = LinearLayout.LayoutParams.WRAP_CONTENT; // 高度
        // 当Window的Attributes改变时系统会调用此函数,可以直接调用以应用上面对窗口参数的更改,也可以用setAttributes
        // dialog.onWindowAttributesChanged(lp);
        dialogWindow.setAttributes(lp);

        Button helper_btn_sure = layout.findViewById(R.id.btn_pay);
        TextView tv_adress = layout.findViewById(R.id.tv_adress);
        TextView tv_payadress = layout.findViewById(R.id.tv_payadress);
        TextView tv_amount = layout.findViewById(R.id.tv_amount);
        tv_adress.setText(address);
        tv_payadress.setText(paywallet);
        tv_amount.setText(amount);

        ImageView img_dilog_diss = layout.findViewById(R.id.img_dilog_diss);
        img_dilog_diss.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                dismiss();
            }
        });
        if (sure_listener !=null){

            helper_btn_sure.setOnClickListener(sure_listener);
        }

        return dialog;

    }

}
